<template>
	<z-paging ref="paging" v-model="dataList" @query="queryList">
		<view class="subsection">
			<up-subsection :list="list" :current="curNow" @change="sectionChange" bgColor="#f2f2f2"
				activeColor="#fff"></up-subsection>
		</view>
		<view class="content">
			<view class="itemList" v-for="(item,index) in dataList" :key="index" @click="detail(item)">
				<view class="top">
					<view class="topLeft">
						{{item.company_name}} <span v-if="item.parkName">({{item.parkName}})</span>
					</view>
					<view class="topRight">
						<up-tag text="待审核" plain v-if="item.status == 0"> </up-tag>
						<up-tag text="处理中" type="warning" plain v-if="item.status == 1"></up-tag>
						<up-tag text="已完成" type="success" plain v-if="item.status == 2"></up-tag>
						<up-tag text="标签" type="error" plain v-if="item.status == 3"></up-tag>
					</view>
				</view>
				<view class="category" v-if="item.categoryName">
					{{item.categoryName}}
				</view>
				<view class="wenzi">
					{{item.description}}
				</view>
				<view class="bottom">
					<view class="bottomLeft">
						<view class="name">
							{{item.contact_name}}
						</view>
						<view class="iphone">
							{{item.contact_phone}}
						</view>
					</view>
					<view class="bottomRight">
						{{item.create_datetime}}
					</view>
				</view>
			</view>
		</view>
		<view class="Post" @click="post">
			新增
		</view>
	</z-paging>
</template>

<script>
	import {
		categoryList,
		parkList,
		getOrder
	} from '../../api/reportedMaintenance.js'
	export default {
		data() {
			return {
				dataList: [],
				list: ['全部', '待处理', '处理中', '已完成', '已关闭'],
				curNow: 0,
				val: '',
				parkData: [],
				categoryData: []
			}
		},
		created() {
			parkList().then((res) => {
				if (res.code == 2000) {
					this.parkData = res.data
				}
			})
			categoryList().then((res) => {
				if (res.code == 2000) {
					this.categoryData = res.data
				}
			})
		},
		onLoad() {
			uni.$once('queryList', () => {
				this.queryList(1,10);
			});
		},
		methods: {
			detail(item){
				uni.navigateTo({
					url:'./details?id=' + item.id
				})
			},
			post(){
				uni.navigateTo({
					url:'./index'
				})
			},
			sectionChange(index) {
				this.curNow = index;
				if (this.curNow == 0) {
					this.val = ''
				} else {
					this.val = Number(index - 1)
				}
				this.queryList(1, 10)
			},
			queryList(pageNo, pageSize) {
				getOrder({
					limit: pageSize,
					page: pageNo,
					status: this.val
				}).then((res) => {
					const parkMap = {};
					const categoryMap = {};
					this.parkData.forEach((item) => {
						parkMap[item.id] = item.name;
					});
					this.categoryData.forEach((item) => {
						categoryMap[item.id] = item.name;
					});
					res.data.forEach((item) => {
						item.parkName = parkMap[item.park] || ''; // 如果找不到对应的 parkName，则赋值为空字符串或其他默认值
						item.categoryName = categoryMap[item.category] || '';
					});
					this.$refs.paging.complete(res.data);
				})
			}
		}
	}
</script>

<style lang="scss">
	.zp-paging-container {
		background-color: #f2f2f2;
	}

	.z-paging-content {
		background-color: #f2f2f2;
	}

	.subsection {
		width: 100vw;
		box-sizing: border-box;
		padding: 20rpx;
		background-color: #f2f2f2;
	}

	:deep(.u-subsection--button__bar) {
		background-color: #c30d23 !important;
	}

	.Post {
		position: fixed;
		right: 80rpx;
		bottom: 300rpx;
		border-radius: 50%;
		width: 100rpx;
		height: 100rpx;
		background-color: #eb8a1d;
		color: #fff;
		line-height: 100rpx;
		text-align: center;
		font-size: 30rpx;
		color: #fff;
	}

	.content {
		padding: 25rpx;

		.itemList {
			padding: 25rpx;
			background-color: #fff;
			border-radius: 10rpx;
			margin-bottom: 20rpx;

			.top {
				display: flex;
				align-items: center;
			}

			.topLeft {
				flex: 1;
				font-size: 30rpx;
				font-weight: 600;
			}

			.category {
				padding: 10rpx 0;
				font-size: 25rpx;
			}

			.wenzi {
				padding: 15rpx 0;
				font-size: 28rpx;
			}

			.bottom {
				display: flex;
				align-items: center;
				font-size: 25rpx;

				.bottomRight {
					flex: 1;
					text-align: right;
				}

				.bottomLeft {
					.name {
						margin-bottom: 10rpx;
					}
				}
			}

		}
	}
</style>